//
//  MTVerificationDeniedViewController.swift
//  MT
//
//  Created by M on 2019/12/24.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import MTCategory
import YPNavigationBarTransition

class MTVerificationDeniedViewController: BaseViewController {
    
    /// Icon
    lazy var iconImageView: UIImageView = {
        let imgView = UIImageView()
        imgView.image = UIImage(named: "icon_question")
        imgView.contentMode = .scaleAspectFill
        return imgView
    }()
    
    /// 标题
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.text = "非常抱歉，您的审核未通过"
        label.font = PingFangSCMediumFont(20)
        label.textColor = UIColor.theme.main
        label.textAlignment = .center
        return label
    }()
    
    /// containerView
    lazy var containerView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: 0x131313)
        return view
    }()
    
    /// 原因
    lazy var reasonLabel: UILabel = {
        let label = UILabel()
        let mas = NSMutableAttributedString()
        let as1 = NSMutableAttributedString(string: "原因可能是\n您提供的审核资料暂不符合荼蘼的")
        as1.setAttributes([.foregroundColor: UIColor.white,
                           .font: PingFangSCRegularFont(14)], range: NSMakeRange(0, as1.length))
        let as2 = NSMutableAttributedString(string: "审核标注")
        as2.setAttributes([.foregroundColor: UIColor.theme.main,
                           .font: PingFangSCRegularFont(14)], range: NSMakeRange(0, as2.length))
        mas.append(as1)
        mas.append(as2)
        label.attributedText = mas
        label.numberOfLines = 2
        label.textAlignment = .left
        return label
    }()
    
    /// 重新验证按钮
    lazy var reverifyButton: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor.theme.main
        btn.setTitle("重新验证", for: .normal)
        btn.setTitleColor(UIColor.text.x161616, for: .normal)
        btn.titleLabel?.font = PingFangSCSemiboldFont(16)
        btn.adjustsImageWhenHighlighted = false
        btn.layer.cornerRadius = 22
        btn.addTarget(self, action: #selector(verificationDeniedViewController(didClickReverifyButton:)), for: .touchUpInside)
        return btn
    }()

    /// tips
    lazy var tipsLabel: UILabel = {
        let label = UILabel()
        label.text = "如有疑问，请关注微信公众号咨询\n感谢您对荼蘼的支持！"
        label.font = PingFangSCRegularFont(12)
        label.textColor = .white
        label.textAlignment = .center
        label.numberOfLines = 2
        return label
    }()
    
}

// MARK: ------------------ Overrides ----------------------
extension MTVerificationDeniedViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initializeUI()
    }
    
    override func yp_navigationBarTintColor() -> UIColor! {
        UIColor(hex: 0xFFFFFF)
    }

    override func yp_navigationBackgroundColor() -> UIColor! {
        .clear
    }

    override func yp_navigationBackgroundImage(withIdentifier identifier: AutoreleasingUnsafeMutablePointer<NSString?>!) -> UIImage! {
        return nil
    }
    
    override func yp_navigtionBarConfiguration() -> YPNavigationBarConfigurations {
        .backgroundStyleTransparent
    }
    
}

// MARK: ------------------ 初始化 ----------------------
extension MTVerificationDeniedViewController {
    
    private func initializeUI() {
        navigationItem.leftBarButtonItem = nil
        
        view.backgroundColor = UIColor.theme.background
        view.addSubview(iconImageView)
        view.addSubview(titleLabel)
        view.addSubview(containerView)
        containerView.addSubview(reasonLabel)
        view.addSubview(reverifyButton)
        view.addSubview(tipsLabel)
        
        iconImageView.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(100)
            make.width.equalTo(122)
            make.height.equalTo(105)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(iconImageView)
            make.top.equalTo(iconImageView.snp.bottom).offset(15)
        }
        
        containerView.snp.makeConstraints { (make) in
            make.left.equalTo(view).offset(15)
            make.right.equalTo(view).offset(-15)
            make.top.equalTo(titleLabel.snp.bottom).offset(15)
        }
        
        reasonLabel.snp.makeConstraints { (make) in
            make.left.equalTo(containerView).offset(40)
            make.right.equalTo(containerView).offset(-40)
            make.top.equalTo(containerView).offset(17)
            make.bottom.equalTo(containerView).offset(-17)
        }
        
        reverifyButton.snp.makeConstraints { (make) in
            make.centerX.equalTo(iconImageView)
            make.top.equalTo(containerView.snp.bottom).offset(65)
            make.width.equalTo(210)
            make.height.equalTo(44)
        }
        
        tipsLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(view).offset(-ScreenBottomExtraOffset - 32)
            make.centerX.equalTo(view)
        }
    }
    
}

// MARK: ------------------ 事件方法 ----------------------
@objc
extension MTVerificationDeniedViewController {
 
    private func verificationDeniedViewController(didClickReverifyButton sender: UIButton) {
        let c = MTVideoVerificationViewController()
        navigationController?.pushViewController(c, animated: true)
    }
    
}
